package net.jueb.frameworkDemo.orm.redis.queue.unPersistent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

public class SubClient {

	protected Logger log=LoggerFactory.getLogger(getClass());
	
	private Jedis jedis;//
	
	public SubClient(String host,int port){
		jedis = new Jedis(host,port);
	}
	
	/**
	 * 此处将会阻塞，在client代码级别为JedisPubSub在处理消息时，
	 * 将会“独占”链接并且采取了while循环的方式，侦听订阅的消息
	 * 直到调用listener.unsubscribe方法才解除阻塞
	 * @param listener
	 * @param channel
	 */
	public void sub(String channel,JedisPubSub listener){
		jedis.subscribe(listener, channel);
	}
}